<!DOCTYPE html>
<title>Verify that attachment filenames are not normalized</title>
<script src="/js-test-resources/js-test.js"></script>
<script>
description(document.title);
var jsTestIsAsync = true;

var request = {
    field: "attachment",
    filename: decodeURIComponent("z%CC%87o%CC%81%C5%82c%CC%81.txt"),
    type: "text/plain",
    content: "hello world"
};
var file = new File([request.content], request.filename, {type: request.type});
shouldBe("file.name", "request.filename");

var data = new FormData();
data.append(request.field, file);

var xhr = new XMLHttpRequest();
var match, response;
xhr.open("POST", "resources/multipart-post-echo.php", true);
xhr.send(data);
xhr.onreadystatechange = function(e) {
    if (xhr.readyState !== xhr.DONE)
        return;
    match = xhr.responseText.match(/^(.*)=(.*):(.*):(.*)$/);
    response = {
        field: match[1],
        filename: match[2],
        type: match[3],
        content: match[4]
    };

    shouldBe("response.field", "request.field");
    shouldBe("response.filename", "request.filename");
    shouldBe("response.type", "request.type");
    shouldBe("response.content", "request.content");
    finishJSTest();
};
</script>
</body>
</html>
